﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.DAL;
using Gift.Model;

namespace WebSite.admin.company
{
    public partial class CompanyMoney : BaseAdmin
    {
      
        readonly dalCompany theCompany = new dalCompany();

        string ParamentType
        {
            get
            {
                return Request.QueryString["type"];
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (ParamentType == "publish")
                {
                    base.ValidateLoginRule(Gift.Model.ENUM.ERule.PublishCompanyMoney);
                }
                else
                {
                    base.ValidateLoginRule(Gift.Model.ENUM.ERule.CompanyMoney);
                }
                try
                {
                    if (Request.QueryString["type"] == "out")
                    {
                        this.lblType.Text = "出账";
                    }
                    else
                    {
                        this.lblType.Text = "入账";
                    }
                    tbCompany oCompany;
                    oCompany = theCompany.GetModel(int.Parse(Request.QueryString["id"]));
                    if (base.CompanyId == oCompany.Id.ToString())
                    {
                        this.txtMoney.Enabled = false;
                        this.txtRemark.Enabled = false;
                        this.ImageButton1.Enabled = false;
                    }
                    this.lblCompanyName.Text = oCompany.Name;
                }
                catch
                {
                    base.Response.Write("<script language='javascript'>alert('非法操作！');window.location.href='companyMoneyList.aspx';</script>");
                }
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string sSQL = "insert into tblCompanyMoney(CompanyId,InMoney,OutMoney,OperateTime,AdminId,Remark) "
                         + " values({0},{1},{2},'{3}',{4},'{5}')";
            float inMoney = 0;
            float outMoney = 0;

            if(Request.QueryString["type"] == "out")
            {
                   outMoney = float.Parse(this.txtMoney.Text);
             
            }else
            {
                   inMoney = float.Parse(this.txtMoney.Text);
            }

            SQLAccess.DoSql(string.Format(sSQL,Request.QueryString["id"],inMoney,outMoney,DateTime.Now.ToString(),base.AdminUserId,this.txtRemark.Text.Trim()));
            base.Response.Write("<script language='javascript'>alert('保存成功');window.location.href='companyMoneyList.aspx';</script>");
        }

      
    }
}